local hx__guizhong = fk.CreateSkill {

  name = "hx__guizhong",

  tags = { Skill.Compulsory, },

}

local hx_jianshen__getjianqi = function (room, player, num)
  local maxnum
  if player:usedSkillTimes("hx__tuiying",Player.HistoryGame) == 0 then
    maxnum = 3 - player:getMark("@hx__jianqi")
  else
    maxnum = 5 - player:getMark("@hx__jianqi")
  end
   local getnum = math.min(maxnum,num)
   room:addPlayerMark(player,"@hx__jianqi",getnum)
end


hx__guizhong:addEffect("active", {
  name = "hx__guizhong",
  anim_type = "offensive",
  prompt = "#hx__guizhong_prompt",
  can_use = function (self, player)
    return player:getMark("@hx__jianqi") >= 2 and player:getMark("@hx__guizhong-turn") == 0 and player:usedSkillTimes(hx__guizhong.name) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = effect.from
    room:removePlayerMark(player,"@hx__jianqi",2)
    room:loseHp(player,1,hx__guizhong.name)
    room:addPlayerMark(player,"@hx__guizhong-turn",1)
  end,
})

hx__guizhong:addEffect(fk.TurnStart, {
  name = "#hx__guizhong_trigger",
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill("hx__guizhong")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    hx_jianshen__getjianqi(room,player,1)
  end,
})

hx__guizhong:addEffect(fk.CardUsing, {
  can_refresh = function (self, event, target, player, data)
      return player:hasSkill("hx__guizhong") and target and target == player and player:getMark("@hx__guizhong-turn") > 0 and data.card and data.card.trueName == "slash"
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
      data.additionalEffect = (data.additionalEffect or 0) + 1
      data.card.skillName = "hx__guizhong"
      room:setPlayerMark(player,"@hx__guizhong-turn",0)
  end,
})

hx__guizhong:addEffect(fk.DamageCaused, {
  can_refresh = function (self, event, target, player, data)
      return player:hasSkill("hx__guizhong") and target and target == player and data.card and data.card.skillName == "hx__guizhong"
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
      local num = math.max(data.to:getLostHp(),2)
      room:loseHp(data.to,num,"hx__guizhong")
      data:preventDamage()
  end,
})

return hx__guizhong